package com.example.a22310.myapplication.ViewModel.Activity;


import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.widget.Toast;

import com.example.a22310.myapplication.Adapter.Drag.RecycleItemTouchHelper;
import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.Choiceness;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.ActivityModel;
import com.example.a22310.myapplication.R;
import com.example.a22310.myapplication.databinding.FragmentActivityChoicenessBinding;

import java.util.List;

public class ActivityChoicenessViewModel implements ActivityLisenter<Choiceness> {
    private FragmentActivityChoicenessBinding binding;
    private FragmentActivity activity;



    public ActivityChoicenessViewModel(FragmentActivityChoicenessBinding activity, FragmentActivity binding){
        this.activity = activity;
        this.binding = binding;
        binding.setModel(this);
        ActivityModel activityModel=new ActivityModel();
        activityModel.activityList(ActivityChoicenessViewModel.this);
    }

    public ActivityChoicenessViewModel(FragmentActivity activity, FragmentActivityChoicenessBinding binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    public ActivityChoicenessViewModel(int activity, int binding) {
    }

    @Override
    public void onSuccess(Choiceness activitys) {
        if(activitys.getCode()!=404){
            List<Choiceness.ActivitydataBean> activitydataBeen =  activitys.getActivitydata();
            binding.recyclerViewActivity.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_activity_choiceness,
                    activitydataBeen, BR.model);
            binding.recyclerViewActivity.setAdapter(adapter);
            ItemTouchHelper.Callback callback=new RecycleItemTouchHelper(adapter);
            ItemTouchHelper itemTouchHelper=new ItemTouchHelper(callback);
            itemTouchHelper.attachToRecyclerView(binding.recyclerViewActivity);

        }

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败", Toast.LENGTH_LONG).show();
    }

